package com.zigong.app.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.zigong.app.R;
import com.zigong.app.beans.NewsItem;
import com.zigong.app.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liuyu on 2017/8/17.
 */

public class RelateHolder extends BaseAbsHolder<NewsItem> implements View.OnClickListener {

    @BindView(R.id.item_relate_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_relate_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_relate_state)
    protected CustomFontTextView state;
    @BindView(R.id.item_relate_time)
    protected CustomFontTextView play_length;
    @BindView(R.id.item_reate_img_media)
    protected ImageView news_type;

    public RelateHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(NewsItem newsItem) {
        title.setText(newsItem.getNewsTitle());
        state.setText(newsItem.getLable());
        GlideUtil.loadImgSmall169Def(context, newsItem.getNewsImage(), img);
        if (!TextUtils.isEmpty(newsItem.getNewsMediaLength())) {
            play_length.setVisibility(View.VISIBLE);
            play_length.setText(newsItem.getNewsMediaLength());
        } else {
            play_length.setVisibility(View.GONE);
        }
        if (newsItem.getNewsType() == 2) { //音频
            news_type.setImageResource(R.mipmap.icon_home_voice);
            news_type.setVisibility(View.VISIBLE);
        } else if (newsItem.getNewsType() == 3) {   //视频
            news_type.setImageResource(R.mipmap.icon_home_play);
            news_type.setVisibility(View.VISIBLE);
        } else {
            news_type.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        doInternalClick(v);
    }

    @Override
    public void onDestory() {
        super.onDestory();
    }
}
